﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sekundomer
{
    class Program
    {
        static void Main(string[] args)
        {
            Stopwatch stopWatch = new Stopwatch();
            Console.WriteLine("Press 'SPACE' to start stopwatch");

            ConsoleKeyInfo keyStart = Console.ReadKey();

            while (keyStart.KeyChar == 32)
            {
                Console.Clear();
                stopWatch.Start();
                Console.WriteLine("Press 'SPACE' to pause stopwatch or 'ESC' to reset stopwatch");
                ConsoleKeyInfo keyPause = Console.ReadKey();
                if (keyPause.KeyChar == 27)
                {
                    Console.Clear();
                    stopWatch.Reset();
                    Console.WriteLine("Press 'SPACE' to start stopwatch");
                    keyStart = Console.ReadKey();
                }

                while (keyPause.KeyChar == 32)
                {
                    Console.Clear();
                    stopWatch.Stop();
                    TimeSpan timeSpan = stopWatch.Elapsed;
                    Console.WriteLine("Press 'SPACE' to start stopwatch or 'ESC' to reset stopwatch");
                    Console.WriteLine("Elapsed seconds: {0:0}", timeSpan.TotalSeconds);
                    ConsoleKeyInfo keyReset = Console.ReadKey();
                    if (keyReset.KeyChar == 27)
                    {
                        Console.Clear();
                        stopWatch.Reset();
                        Console.WriteLine("Press 'SPACE' to start stopwatch");
                        keyStart = Console.ReadKey();
                    }
                    break;
                }
            }
        }
    }
}